<template>
	<view   customStyle="padding: 32rpx;"> 
			<u-row> 
			<u-col span="5">
				<u--image v-if="shopDetails.picture" :showLoading="true" :src="shopDetails.picture" width="250rpx" height="250rpx" @click="click"></u--image>
				<u--image v-else :showLoading="true" src="/static/imgs/log.png" width="250rpx" height="250rpx" @click="click"></u--image>
			</u-col>
			<u-col span="5"  >
				<u-row>
					<u--text :text="shopDetails.goods_name" size="17"></u--text>
				</u-row>
				<u-row  customStyle="margin-top: 16rpx;">
					<u-col span="12">
						<u--text text="条形码:" size='12'></u--text>
					</u-col>
					 
				</u-row>
				<u-row>
					<u-col span="12">
						<u--text :text="shopDetails.bar_code || '暂无'" size='13' color="#e89b00" bold></u--text>
					</u-col>
				</u-row>
				<u-row customStyle="margin-top: 16rpx;">
					<u-col span="12">
						<u--text v-if='shopDetails.quality_guarantee_period' :text="'保质期:'+shopDetails.quality_guarantee_period" size='12'></u--text>
						<u--text v-else text=" 保质期: 未设置" size='12'></u--text>
					</u-col>
					 
				</u-row>
				<u-row customStyle="margin-top: 32rpx;white-space: nowrap;"  >
					<u-col span="12">
						<u--text v-if="shopDetails.unit" :text="'单位：' +shopDetails.unit" size='12'></u--text>
						<u--text v-else text="单位：未设置" size='12'></u--text>
					</u-col>
					 
				</u-row>
			</u-col>
		</u-row>
		<u-row   customStyle="margin-top: 32rpx;">
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="生产日期: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text v-if="shopDetails.manufacture_date " mode="date" :text="Number(shopDetails.manufacture_date )" size='14' color="#008200" bold=""></u--text>
						<u--text v-else   text=" 暂无" size='14' color="#008200" bold=""></u--text>
					</u-col>
				</u-row>
			</u-col>
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="转临日期: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text text="暂无" size='14' color="#050782" bold></u--text>
					</u-col>
				</u-row>
				 
			</u-col> 
		</u-row>
		<u-row   customStyle="margin-top: 16rpx;">
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="下架日期: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text text="暂无" size='14' color="#ffaa00" bold></u--text>
					</u-col>
				</u-row>
			</u-col>
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text  text="过期日期: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text v-if="shopDetails.expiration_date" mode="date" :text="Number(shopDetails.expiration_date) " size='14' color="#aa0000" bold></u--text>
						<u--text  v-else text=" 暂无 " size='14' color="#aa0000" bold></u--text>
					</u-col>
				</u-row>
				 
			</u-col> 
		</u-row>
		<u-row    customStyle="margin-top: 16rpx;">
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="录入人员: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text :text="shopDetails.employ" size='13'  ></u--text>
					</u-col>
				</u-row>
			</u-col>
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="录入时间: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text mode="date" :text="Number(shopDetails.add_time)" size='13'  ></u--text>
					</u-col>
				</u-row>
				 
			</u-col> 
		</u-row>
		<u-row    customStyle="margin-top: 16rpx;">
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="修改人员: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text :text="shopDetails.updated_by || '暂无'" size='13'  ></u--text>
					</u-col>
				</u-row>
			</u-col>
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="修改时间: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text mode="date" :text="shopDetails.update_time" size='13'  ></u--text>
					</u-col>
				</u-row>
				 
			</u-col> 
		</u-row>
		<u-row    customStyle="margin-top: 16rpx;">
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="供应商: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text :text="shopDetails.manufacturer||'暂无'" size='14' color="#ffaa00" ></u--text>
					</u-col>
				</u-row>
			</u-col>
			<u-col span="6" >
				<u-row>
					<u-col span="4">
						<u--text text="进货数量: " size='13'></u--text>
					</u-col>
					<u-col span="8"  >
						<u--text :text="shopDetails.buy_number" size='14' color="#ffaa00"></u--text>
					</u-col>
				</u-row>
				 
			</u-col> 
		</u-row>
		<u-row  customStyle="margin-top: 32rpx;">
			<u-col span="3">
				<u--text text="当前库存: " size='13' ></u--text>
			</u-col >
			<u-col span="5">
			 <u--input
					type='number'
					v-model="shopDetails.stock"
					:clearable='true'
					border="bottom"
					suffixIconStyle="color: #909399"
				></u--input>
			</u-col>
			<u-col span="2" offset="1"  >
			 <u-button type="success" text="调整" size="normal" @click="changeStock"></u-button>
			</u-col>
		</u-row>
		<u-row customStyle="margin-top: 32rpx;">
			<u-col span="3">
				<u--text text="零售价格: " size='13'></u--text>
			</u-col >
			<u-col span="5">
			 <u--input
					:clearable='true'
					border="bottom"
					v-model="shopDetails.retail_price"
					suffixIconStyle="color: #909399"
				></u--input>
			</u-col>
			<u-col span="2" offset="1" >
			 <u-button type="success" text="调整"  @click="changePrice"></u-button>
			</u-col>
		</u-row>
		<!-- <u-row customStyle="margin-top: 32rpx;">
			<u-col span="3">
				<u--text text="货架号: " size='13'></u--text>
			</u-col >
			<u-col span="6" @click='schooseShelf = true'>
			 <u--input
					:clearable='true'
					 v-model="shopDetails.goods_shelves_name"
					 :disabled='true'
					
					border="bottom"
					suffixIconStyle="color: #909399"
				></u--input>
			</u-col>
			<u-col span="2" offset="1">
			 <u-button type="success" text="调整" @click="changeShelf"></u-button>
			</u-col>
		</u-row> -->
	 
		
		
		<u-row customStyle="margin-top: 32rpx;" >
			<u-col span="10" offset="1">
				<u-button type="error" shape='circle' @click="userOff" text="删除"></u-button>
			</u-col>
		</u-row>
		<!-- <u-row class="u-m-t-20" justify='center'>
			<u-col span="10">
				<u-button type="success" shape='circle'  text="查看各大电商信息"></u-button>
			</u-col>
		</u-row> -->
		<u-modal :show="modalShow"  title='提示'
				cancelText='取消' 
				@cancel='cancel' 
				:showCancelButton='true' 
				confirmText='确认'  
				:content='mContent'
				@close='cancel'
				@confirm="confirm" ref="uModal" 
				:asyncClose="true"></u-modal>
				<u-popup mode='right' :show="schooseShelf" @close="schooseShelf = false" @open="open" >
						
						<view style="width: 400rpx;padding: 30rpx;">
							<u--input
									@change = 'shelf'
								    placeholder="前置图标"
									
								    prefixIcon="search"
								    prefixIconStyle="font-size: 22px;color: #909399"
								></u--input>
							 <u-row class="u-m-t-15" v-for="(item,index) in fillterShelfList" :key="index">
								 <u-col span="8">
									 <u--text :text="item.shelves_name">
										 
									 </u--text>
								 </u-col>
								 <u-col span="4">
									 <u-button type="primary" text="选择" @click="shopDetails.goods_shelves_id = item.id;shopDetails.goods_shelves_name = item.shelves_name "></u-button>
								 </u-col>
							 </u-row>
						</view>
					</u-popup>
	</view>
</template>

<script>
	var that
  var ERgoodsShelf = require('../../../service/ERgoodsShelf'),mERgoodsShelf
	var ERGoodsScan = require('../../../service/ERGoodsScan'),mERGoodsScan
	export default {
		data() {
			return {
				schooseShelf:false,
				shelfList:[],
				fillterShelfList:[],
				shopDetails:{
					stock:0,
					unit:'',
					bar_code: '',
					goods_name: '',
					buy_number: 0,
					batch_number:'',
					quality_guarantee_period: '  ',
					product_brand: '',
					manufacturer: '',
					goods_type: '',
					manufacture_date: '', 
					expiration_date: '',
					specifications: '',
					price:null,
					retail_price:null,
					goods_shelves_name:'',
					goods_shelves_id:0
				},
				shopNum:30,
				mContent:'注意该操作不可挽回，是否继续？',
				modalShow: false,
				userInfo:{}
				 
			}
		},
		onLoad() {
			that = this
			mERgoodsShelf = new ERgoodsShelf(this.mNetTool)
			mERGoodsScan = new ERGoodsScan(this.mNetTool)
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo')
			that.userInfo = userInfo
			let addInfo = {
				created_by:userInfo.id,
				
			}
			that.shopDetails = uni.getStorageSync('shopDetails')
			// mERgoodsShelf.list(addInfo,res => {
			// 	console.log(res)
			// 	that.fillterShelfList = res.rows
			// 	that.shelfList = res.rows 
			// })
		},
		methods: {
			shelf(e){
				that.fillterShelfList = that.shelfList.filter(item => {
					return item.shelves_name.indexOf(e) != -1
				})
			},
			//修改货架
			changeShelf(){
				 uni.showToast({
					 title:'请稍等',
					 icon:'loading',
					 duration:3000
				 })
				let info = {
					id : that.shopDetails.id,
					goods_shelves_id : that.shopDetails.goods_shelves_id,
					updated_by:that.userInfo.nick_name
				}
				mERGoodsScan.update(info,res => {
					if(res.success){
						uni.hideToast()
						uni.$u.toast('修改成功')
					}
				})
			},
			//修改零售价
			changePrice(){
				 uni.showToast({
					 title:'请稍等',
					 icon:'loading',
					 duration:3000
				 })
				let info = {
					id : that.shopDetails.id,
					retail_price : that.shopDetails.retail_price,
					updated_by:that.userInfo.nick_name
				}
				mERGoodsScan.update(info,res => {
					if(res.success){
						uni.hideToast()
						uni.$u.toast('修改成功')
					}
				})
			},
			//修改库存
			 changeStock(){
				 uni.showToast({
					 title:'请稍等',
					 icon:'loading',
					 duration:3000
				 })
				let info = {
					id : that.shopDetails.id,
					stock : that.shopDetails.stock,
					updated_by:that.userInfo.nick_name
				}
				mERGoodsScan.update(info,res => {
					if(res.success){
						uni.hideToast()
						uni.$u.toast('修改成功')
					}
				})
			},
			drop(){
				
			},
			cancel(){
				this.modalShow = false
			},
			confirm(){
				 uni.switchTab({
				 	url:'../home/home'
				 })
			},
			userOver(){
				this.modalShow = true
				
			},
			userOff(){
				let shopDetails = uni.getStorageSync('shopDetails')
				if(shopDetails.id){
					uni.showModal({
						title: '提示',
						content: '此操作不可逆，是否继续删除',
						success: res => {
							if(res.confirm){
								mERGoodsScan.del({
									id:shopDetails.id
								},res=>{
									if(res.success){
										uni.$u.toast('删除成功')
										uni.navigateBack({
											
										})
									}
								})
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}
				// console.log(that.shopDetails.statue)
				// let info = {
				// 	id : that.shopDetails.id,
				// 	statue : 1
				// }
				// if(that.shopDetails.status){
				// 	info.statue = 0
				// }else{
				// 	info.statue = 1
				// }
				// mERGoodsScan.update(info,res => {
				// 	if(res.success){
				// 		uni.$u.toast('修改成功')
				// 	}
				// })
				
			},
			inputNum( ){
				console.log(this.shopNum  )
				if(this.shopNum < 0) {
					this.shopNum = 0
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		padding:0 32rpx;
	}
	.container {
		padding: 32rpx;
	}

</style>
